package com.kk.xhr.model.dao;

import com.kk.xhr.model.entity.RecruitInterview;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.kk.xhr.model.dao.RecruitInterviewDynamicSqlSupport.id;
import static com.kk.xhr.model.dao.RecruitInterviewDynamicSqlSupport.interviewerId;
import static com.kk.xhr.model.dao.RecruitInterviewDynamicSqlSupport.recruitId;
import static com.kk.xhr.model.dao.RecruitInterviewDynamicSqlSupport.recruitInterview;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface RecruitInterviewMapper {
    @InsertProvider(type = SqlProviderAdapter.class, method = "insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<RecruitInterview> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    BasicColumn[] selectList = BasicColumn.columnList(id, recruitId, interviewerId);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Long.class)
    int insert(InsertStatementProvider<RecruitInterview> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("RecruitInterviewResult")
    Optional<RecruitInterview> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="RecruitInterviewResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="recruit_id", property="recruitId", jdbcType=JdbcType.BIGINT),
        @Result(column="interviewer_id", property="interviewerId", jdbcType=JdbcType.BIGINT)
    })
    List<RecruitInterview> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, recruitInterview, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, recruitInterview, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default int insert(RecruitInterview record) {
        return MyBatis3Utils.insert(this::insert, record, recruitInterview, c ->
            c.map(recruitId).toProperty("recruitId")
            .map(interviewerId).toProperty("interviewerId")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default int insertSelective(RecruitInterview record) {
        return MyBatis3Utils.insert(this::insert, record, recruitInterview, c ->
            c.map(recruitId).toPropertyWhenPresent("recruitId", record::getRecruitId)
            .map(interviewerId).toPropertyWhenPresent("interviewerId", record::getInterviewerId)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default Optional<RecruitInterview> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, recruitInterview, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default List<RecruitInterview> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, recruitInterview, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default List<RecruitInterview> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, recruitInterview, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default Optional<RecruitInterview> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, recruitInterview, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    static UpdateDSL<UpdateModel> updateAllColumns(RecruitInterview record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(recruitId).equalTo(record::getRecruitId)
                .set(interviewerId).equalTo(record::getInterviewerId);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(RecruitInterview record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(recruitId).equalToWhenPresent(record::getRecruitId)
                .set(interviewerId).equalToWhenPresent(record::getInterviewerId);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default int updateByPrimaryKey(RecruitInterview record) {
        return update(c ->
            c.set(recruitId).equalTo(record::getRecruitId)
            .set(interviewerId).equalTo(record::getInterviewerId)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit_interview")
    default int updateByPrimaryKeySelective(RecruitInterview record) {
        return update(c ->
            c.set(recruitId).equalToWhenPresent(record::getRecruitId)
            .set(interviewerId).equalToWhenPresent(record::getInterviewerId)
            .where(id, isEqualTo(record::getId))
        );
    }
}
